//
//  RenYuanEduitVC.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/9.
//

#import "RenYuanEduitVC.h"
#import "CommonTableViewCell.h"
#import "GeRenXinXiVC.h"
#import "ChangePassVC.h"
#import "ChangePhoneVC.h"
@interface RenYuanEduitVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataAry;
@property (nonatomic, strong) YLUserInfo * info;

@end

@implementation RenYuanEduitVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
   
    self.info = [YLUserMgr fetchUser];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = White_Color;
    [self layoutCustomNav:self.view title:@"用户编辑"];
     self.dataAry = [NSMutableArray arrayWithArray:@[@"个人信息",@"修改密码",@"修改手机"]];
    [self createTableView];
}

-(void)createTableView{
    self.tableView = [[UITableView  alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight+10, ScreenWidth, B_HEIGHT - LL_StatusBarAndNavigationBarHeight - LL_TabbarSafeBottomMargin - 10)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.backgroundColor = White_Color;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:[CommonTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    [self.view addSubview:self.tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataAry.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
     return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CommonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[CommonTableViewCell reuseIdentifier]];
    if (!cell) {
        cell = [[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    }
    cell.nameLb.text = self.dataAry[indexPath.row];
    cell.contentTF.userInteractionEnabled = NO;
    if (indexPath.row == 0 || indexPath.row == 1) {
        cell.contentTF.hidden = YES;
    } else {
        cell.contentTF.hidden = NO;
        cell.contentTF.text = self.userInfo.loginNo;
    }
    if (indexPath.row == 0) {
        cell.nameLb.textColor = mainColor;
    } else {
        cell.nameLb.textColor = Black_Color;
    }
    if (indexPath.row == 2) {
        cell.contentTF.text = self.info.telePhone;
    }
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    cell.indexPath = indexPath;
    [cell setCurrentValueBlock:^(NSString * _Nonnull contentString, NSIndexPath * _Nonnull indexPath) {
   
    }];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [CommonTableViewCell cellHeight];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            GeRenXinXiVC *VC = [[GeRenXinXiVC alloc] init];
            [self pushToNextController:VC];
        }
        break;
        case 1:
        {
            ChangePassVC *VC = [[ChangePassVC alloc] init];
            [self pushToNextController:VC];
        }
        break;
        case 2:
        {
            ChangePhoneVC *VC = [[ChangePhoneVC alloc] init];
            [self pushToNextController:VC];
        }
        break;
        default:
        break;
    }
}



@end
